<?php
//include Header
$path = $_SERVER['DOCUMENT_ROOT'];
include("$path/header.php");

$klantnummer = $_POST['klantnummer'];
$sOrderDescription = "Aantal		Product naam";
$query = mysql_query("select producten.productnaam,mandje.aantal from producten,mandje where producten.productnummer = mandje.productnummer and klantnummer = $klantnummer",$server);
while($row = mysql_fetch_array($query)){
	$sOrderDescription .= $row['aantal'] . "		" . $row['productnaam'] . "\n";
}
$sOrderId = 0;
$query = mysql_query("select max(bestellingsnummer) as 'max' from bestellingen",$server);
while($row = mysql_fetch_array($query)){
	$sOrderId = $row['max'];
}
$sOrderId++;
mysql_query("insert into bestellingen values ($sOrderId, $klantnummer, 1,1,now(),'','',1)",$server);
$query = mysql_query("select productnummer, aantal from mandje where klantnummer = $klantnummer",$server);
$regelnummer = 1;
while($row = mysql_fetch_array($query)){
	$prijs = 0;
	$prijsquery = mysql_query("select prijs from productprijs where productnummer = " . $row['productnummer'] . " order by datum desc limit 1",$server);
	while($rowprijs = mysql_fetch_array($prijsquery)){
		$prijs = $rowprijs['prijs'];
	}
	mysql_query("insert into bestelregel values ($regelnummer, $sOrderId," . $row['productnummer'] . ", $prijs, " . $row['aantal'] . ")",$server);
	//echo "insert into bestelregel values ($regelnummer, $sOrderId," . $row['productnummer'] . ", $prijs, " . $row['aantal'] . ")";
	$regelnummer++;
}
mysql_query("delete from mandje where klantnummer = $klantnummer",$server);
$fOrderAmount = $_POST['bedrag'];

?>

<form action="IDEAL2.php" method="post">
	<h1>iDEAL - Aankoop betalen [stap 1 van 3]</h1>
	<p>
		<b>
			Order ID:
			<br />
			<input type="text" name="order_id" size="30" value="<?php echo $sOrderId; ?>">
			<br />
			<br />Order bedrag:<br />
			<input name="order_amount" size="30" type="text" value="<?php echo number_format($fOrderAmount, 2, ',', ''); ?>">(EUR)
			<br />
			<br />
			<br />
			<input name="_submit" type="submit" value="verder &gt;&gt;"></b></p>
</form>
<?php
//include footer
include("$path/footer.php");
?>
